home *** CD-ROM | disk | FTP | other *** search
/ TPUG - Toronto PET Users Group / TPUG Users Group CD / TPUG Users Group CD.iso / AMIGA / AMICUS / AMICUS02.ADF / Asm / qsortest.c < prev    next >
C/C++ Source or Header  |  1989-05-30  |  1KB  |  48 lines

  1. /*
  2.    A program to test the qsort "quick-sort" procedure called from Lattice
  3.      Gary Sarff   12/07/85  Compuserve PPN: 70167,2216
  4.  
  5.         Compile this program with something similar to
  6.         copy qtest.c to ram:
  7.         copy qsort.o to ram:
  8.         :c/lc1 -i:include/ -i:include/lattice/ ram:qtest
  9.         :c/lc2 ram:qtest
  10.         :c/alink :lib/lstartup.obj,ram:test.o,ram:qsort.o library
  11.           :lib/lc.lib,:lib/amiga.lib to ram:test map nil:
  12.  
  13.         when you run qtest it should produce
  14.         15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
  15.         Sorting...
  16.         Finished
  17.         0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
  18. */
  19.  
  20. #include <stdio.h>
  21. extern qsort();
  22.  
  23. int array[] = {15,14,13,12,11,10,9,8,7,6,5,4,3,2,1,0};  /* test array */
  24.  
  25. int compfunc(first,second)
  26. int *second,*first;
  27. {
  28.    if ((*first) < (*second)) return(-1);
  29.      else
  30.    if ((*first) == (*second)) return  0;
  31.      else
  32.    if ((*first) > (*second)) return  1;
  33. }
  34. main()
  35. {
  36.    int i;
  37.    unsigned int arsize;
  38.    arsize=sizeof(array)/sizeof(int);
  39.    for (i=0;i < arsize; i++)
  40.      printf("%d ",array[i]);
  41.    printf("\nSorting...\n");
  42.    qsort(&array[0],arsize,sizeof(int),compfunc);
  43.    printf("finished\n");
  44.    for (i=0;i < arsize; i++)
  45.      printf("%d ",array[i]);
  46.    printf("\n");
  47. }
  48.